package com.hinnotek.amoeba.ui.activity.old

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.databinding.ActivityPaymentRequestAddBinding
import com.hinnotek.amoeba.utilities.ClickUtil
import com.hinnotek.amoeba.utilities.IntentUtils
import com.hinnotek.amoeba.utilities.ToastUtils
import com.xuexiang.xutil.common.StringUtils

class PaymentRequestAddActivity : BaseActivity<ActivityPaymentRequestAddBinding>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLeftVisible(true)
        setTitle("添加付款申请")

        setContentView(R.layout.activity_payment_request_add)
    }

    override fun initVew() {

        bindingView.rbPrPj.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                bindingView.llChooseContract.visibility = View.GONE
                bindingView.llChooseUnit.visibility = View.GONE
            }
        }
        bindingView.rbPrC.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                bindingView.llChooseContract.visibility = View.VISIBLE
                bindingView.llChooseUnit.visibility = View.VISIBLE
            }
        }
        bindingView.inLayout.tvPaymentHopeDate.setOnClickListener {
            IntentUtils.startActivityForResult(
                this,
                MaterialDesignCalendarActivity::class.java, null, 111
            )
        }
        bindingView.superButtonSubmit.setOnClickListener(View.OnClickListener { v: View? ->
            if (ClickUtil.isFastClick()) {
                return@OnClickListener
            }
            if (bindingView.rbPrC.isChecked) {
                val escPaymentChooseContractS =
                    bindingView.escPaymentChooseContract.editText.text.trim()
                if (StringUtils.isEmpty(escPaymentChooseContractS)) {
                    ToastUtils.show(mContext, "请选择合同")
                    return@OnClickListener
                }
                val charSequence = bindingView.escPaymentChooseUnit.editText.text.trim()
                if (StringUtils.isEmpty(charSequence)) {
                    ToastUtils.show(mContext, "请选择签署单位")
                    return@OnClickListener
                }
            }
            val escPaymentChooseProjectS = bindingView.escPaymentChooseProject.editText.text.trim()
            if (StringUtils.isEmpty(escPaymentChooseProjectS)) {
                ToastUtils.show(mContext, "请选择选择项目")
                return@OnClickListener
            }
            val tvPaymentHopeDateS = bindingView.inLayout.tvPaymentHopeDate.text.trim()
            if (StringUtils.isEmpty(tvPaymentHopeDateS)) {
                ToastUtils.show(mContext, "请选择期望付款日期")
                return@OnClickListener
            }
            val metPaymentCauseS = bindingView.inLayout.metPaymentCause.contentText.trim()
            if (StringUtils.isEmpty(metPaymentCauseS)) {
                ToastUtils.show(mContext, "请填写付款事由")
                return@OnClickListener
            }
            val etPaymentTotalS = bindingView.inLayout.etPaymentTotal.text.trim()
            if (StringUtils.isEmpty(etPaymentTotalS)) {
                ToastUtils.show(mContext, "请填写付款总额")
                return@OnClickListener
            }
            val escPaymentRelatedApproverS =
                bindingView.inLayout.escPaymentRelatedApprover.editText.text.trim()
            if (StringUtils.isEmpty(escPaymentRelatedApproverS)) {
                ToastUtils.show(mContext, "请选择关联审批人")
                return@OnClickListener
            }
        })
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            when (requestCode) {
                111 -> bindingView.inLayout.tvPaymentHopeDate.setText(data?.getStringExtra("date"))
            }
        }
    }

    override fun setData() {}
}